// 通道实验室

package lab

import (
    "fmt"
    "time"

    "tokyo/common"
)


func ChannelMain() {
    // 向通道中写入数值
    go writeChan()

    // 打印通道的数值
    go printChan()
    time.Sleep(3 * time.Second)
}

// 向通道中写入数值
func writeChan()  {
    time.Sleep(1 * time.Second)
    common.SeqChan <- 33333
    // close(common.SeqChan)
}

func printChan()  {
    LOOP2:
        for {
            select {
            case v, ok := <- common.SeqChan:
                fmt.Println("Get the channel common.SeqChan")
                fmt.Printf("common.SeqChan = %d\n", v)
                fmt.Println("ok =", ok)
                break LOOP2
            default:
                fmt.Println("Waitting for channel common.SeqChan")
                time.Sleep(300 * time.Millisecond)
            }
        }
    fmt.Println("common.SeqChan通道中没有数据了，循环退出")
}
